/**
 * @description: curry
 * @author: huen2015
 */

import { IFn } from './types'

function curry(fn: IFn, ...args: any[]): IFn | any {
	const fnLength = fn.length
	return function (this: any, ...otherArgs: any[]) {
		const tempArgs = [...args, ...otherArgs]
		if (tempArgs.length < fnLength) {
			return curry(fn, ...tempArgs)
		} else {
			return fn.apply(this, tempArgs.slice(0, fnLength))
		}
	}
}

function fn1(a: string, b: string, c: string) {
	console.log(a, b, c)
}

console.info('curry - begin')
curry(fn1)('a', 'b')('c')
console.info('curry - end')
